import service from "./config/request"
// import type { MenuData } from "./menu"
import { ApiResponse } from "./type"
// 1. role 和 access 对应关系 ts 接口
export interface IRoleAccess {
  id: number
  access_id: number
  role_id: number
}
// 2. role 和 access 对应关系 数组  ts 接口
export type IRoleAccessList = IRoleAccess[]

// 3. 获取角色对应权限
export const getRoleAccess = (
  id: number
): Promise<ApiResponse<IRoleAccessList>> => {
  return service.get(`/role_access/${id}`)
}
// 4. 给角色分配权限
export const allocRoleAccess = (
  id: number,
  data: number[]
): Promise<ApiResponse> => {
  return service.post(`/role_access/${id}`, {
    access: data
  })
}
// 角色id对应的权限
export const getRoleAccessByRoles = (
  roles: number[]
): Promise<ApiResponse<{ access: IAccess[] }>> => {
  return service.post(`/role_access/role/access`, {
    roles
  })
}

interface IAccess {
  id: number

  type: number

  title: string

  path: string

  icon: string

  name: string

  sort_id: number

  parent_id: number

  status: number

  description: string
}
